#include "Pion.h"
#include <iostream>
using namespace std;

Pion::Pion(){}

Pion::Pion(int x,int y, bool white)
{
    m_x = x;
    m_y = y;
    m_white = white;
}

char
Pion::tostring()
{
    return( isWhite() ? 'P' : 'p');
}

void
Pion::affiche()
{
    cout << "Pion: x=" << m_x << " y=" << m_y << " "
         << ( isWhite() ? "blanche" : "noire" ) << endl;

}

bool
Pion::mouvementvalide(Echiquier *e, int x, int y )
{
    if(m_white)
        {
            return ( (e->getPiece(m_x + 1,m_y + 1) != 0 && m_x + 1 == x  && m_y +1 == y)

                    || (e->getPiece(m_x - 1,m_y + 1) != 0 && m_x - 1 == x  && m_y + 1== y)

                    || (m_y == 2 && (y == m_y + 1 || y == m_y + 2) && x == m_x)

                    || (y == m_y + 1 && x == m_x) );
        }
        else
        {
            return ( ( ( (e->getPiece(m_x + 1,m_y - 1) != 0) && (m_x +1 == x  && m_y - 1 == y) )
                       || ( (e->getPiece(m_x - 1,m_y - 1) != 0) && (x == m_x - 1 && y == m_y - 1) ) )

                    || ( (m_y == 7) && ( (m_x == x) && (y == m_y - 1) && (e->getPiece(x,y) == 0) || (y == m_y - 2) && (e->getPiece(x,y) == 0) && (m_x == x) )
                         && (e->getPiece(x,y) == 0) )

                    || ( (y = m_y - 1) && (e->getPiece(x,y) == 0) && (m_x == x) ) );

        }

}

Pion::~Pion()
{
    //dtor
}
